<template>
  <div class="container">
    <!-- 数据大屏内容区域 -->
    <div class="screen" ref="screenRef">
      <div class="header">
        <Top></Top>
      </div>
      <div class="main">
        <div class="left">
          <Tourist class="tourist"></Tourist>
          <Gender class="gender"></Gender>
          <Age class="age"></Age>
        </div>
        <!-- 中间区域 -->
        <div class="center">
          <Map class="map"></Map>
          <Future class="future"></Future>
        </div>
        <div class="right">
          <Rank class="rank"></Rank>
          <Year class="year"></Year>
          <Count class="count"></Count>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onUnmounted } from 'vue'
import Top from './components/top/index.vue'
//左侧子组件
import Tourist from './components/tourist/index.vue'
import Gender from './components/gender/index.vue'
import Age from './components/age/index.vue'
// 中间子组件
import Map from './components/map/index.vue'
import Future from './components/future/index.vue'
// 右侧组件
import Rank from './components/rank/index.vue'
import Year from './components/year/index.vue'
import Count from './components/count/index.vue'

// 获取screenRef的DOM元素
const screenRef = ref()

const scale = (w = 1920, h = 1080) => {
  const ww = window.innerWidth / w
  const wh = window.innerHeight / h
  return ww < wh ? ww : wh
}

const updateScale = () => {
  if (screenRef.value) {
    screenRef.value.style.transform = `scale(${scale()}) translate(-50%, -50%)`
  }
}

onMounted(() => {
  updateScale()
  window.addEventListener('resize', updateScale)
})

onUnmounted(() => {
  window.removeEventListener('resize', updateScale)
})
</script>

<style lang="scss" scoped>
.container {
  width: 100vw;
  height: 100vh;
  background: url('./images/bg.png') no-repeat;
  background-size: cover;

  .screen {
    position: fixed;
    width: 1920px;
    height: 1080px;
    transform-origin: left top;
    left: 50%;
    top: 50%;
    display: flex;
    flex-direction: column;

    .header {
      width: 100%;
      height: 40px;
    }

    .main {
      flex: 1;
      display: flex;

      .right {
        flex: 1;
        display: flex;
        flex-direction: column;
        .rank {
          flex: 1.2;
        }
        .year {
          flex: 1;
          background-color: bisque;
        }
        .count {
          flex: 1;
          background-color: cadetblue;
        }
      }
      .left {
        flex: 1;
        height: 1040px;
        display: flex;
        flex-direction: column;
        .tourist {
          flex: 1.2;
        }
        .gender {
          flex: 1;
        }
        .age {
          flex: 1;
        }
      }

      .center {
        flex: 2.5;
        display: flex;
        flex-direction: column;
        // margin-top: 35px;
        margin: 30px;
        .map {
          flex: 3;
        }
        .future {
          flex: 1;
        }
      }
    }
  }
}
</style>
